const express = require('express');
const router = express.Router();
const deviceController = require('../controllers/deviceController');
const authMiddleware = require('../middleware/authMiddleware');

// 获取所有设备列表
router.get('/', authMiddleware.authenticateToken, deviceController.getAllDevices);

// 获取特定房间的设备
router.get('/room/:roomArea', authMiddleware.authenticateToken, deviceController.getDevicesByRoom);

// 获取特定类型的设备
router.get('/type/:deviceType', authMiddleware.authenticateToken, deviceController.getDevicesByType);

// 获取设备参数历史记录
router.get('/parameters/history', authMiddleware.authenticateToken, deviceController.getDeviceParametersHistory);

// 添加新设备
router.post('/', authMiddleware.authenticateToken, deviceController.addDevice);

// 发现并连接设备
router.post('/discover', authMiddleware.authenticateToken, deviceController.discoverAndConnectDevice);

// 通用设备控制
router.post('/:deviceId/control', authMiddleware.authenticateToken, deviceController.controlDevice);

// MQTT命令控制设备
router.post('/:deviceId/mqtt-command', authMiddleware.authenticateToken, deviceController.sendMQTTCommand);

// 获取特定设备信息
router.get('/:deviceId', authMiddleware.authenticateToken, deviceController.getDeviceById);

// 更新设备信息
router.put('/:deviceId', authMiddleware.authenticateToken, deviceController.updateDevice);

// 删除设备
router.delete('/:deviceId', authMiddleware.authenticateToken, deviceController.deleteDevice);

// 控制设备开关
router.post('/:deviceId/power', authMiddleware.authenticateToken, deviceController.toggleDeviceStatus);

// 控制空调设备
router.post('/:deviceId/air-conditioner', authMiddleware.authenticateToken, deviceController.controlAirConditioner);

// 控制加湿器设备
router.post('/:deviceId/humidifier', authMiddleware.authenticateToken, deviceController.controlHumidifier);

// 控制空气净化器设备
router.post('/:deviceId/air-purifier', authMiddleware.authenticateToken, deviceController.controlAirPurifier);

// 控制智能窗户设备
router.post('/:deviceId/window', authMiddleware.authenticateToken, deviceController.controlSmartWindow);

// 控制智能窗帘设备
router.post('/:deviceId/curtain', authMiddleware.authenticateToken, deviceController.controlSmartCurtain);

module.exports = router;